import { defineStore } from 'pinia'

const useHome=defineStore("home",{
    state:()=>({
        banners:[],
        recommends:[]
    }),
    actions:{
        async fetchHomeMultidata(){ // async返回一个promise
            const res=await fetch("http://123.207.32.32:8000/home/multidata")
            const data=await res.json()
            console.log("fetchHomeMultidata:",data)
            this.banners=data.data.banner.list
            this.recommends=data.data.recommend.list
            // 这里相当于return undefined 被promise包裹，类似于return Promise.resolve(undefined)
            // 我这里返回一个A
            return "A"
        }

        // // 实在不好理解可以这样做
        // fetchHomeMultidata(){
        //     return new Promise(async(resolve,reject)=>{
        //         const res=await fetch("http://123.207.32.32:8000/home/multidata")
        //         const data=await res.json()
        //         console.log("fetchHomeMultidata:",data)
        //         this.banners=data.data.banner.list
        //         this.recommends=data.data.recommend.list
        //         resolve("B")
        //     })
        // }
    }
})

export default useHome